package com.zhao.modleclass.presenter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.util.Log;

import com.zhao.modleclass.adapter.HP_LiveAdapter;
import com.zhao.modleclass.adapter.HP_NewAdapter;
import com.zhao.modleclass.adapter.HP_SelectedAdapter;
import com.zhao.modleclass.adapter.HP_TeacherLeft_Adapter;
import com.zhao.modleclass.adapter.HP_TeacherRight_Adapter;
import com.zhao.modleclass.bean.HomePageBean;
import com.zhao.modleclass.modle.IModle_HomePage;
import com.zhao.modleclass.modle.Modle_HomePage;
import com.zhao.modleclass.modle.OnLoadHomepageDataListener;
import com.zhao.modleclass.view.IHomePageView;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2016/11/27.
 */

public class Presenter_HomePage {
    private IModle_HomePage modle_homePage;
    private IHomePageView iHomePageView;
    private List<HomePageBean.DataBean> list_DataBeanSave = new ArrayList<>();
    private HP_NewAdapter adapter_New;

    public Presenter_HomePage(IHomePageView iHomePageView) {
        this.iHomePageView = iHomePageView;
        this.modle_homePage = new Modle_HomePage();
    }

    public void LoadData(final Context context, Map<String, String> map, final RecyclerView recyclerView) {
        modle_homePage.loadHomepageData(map, new OnLoadHomepageDataListener() {
            @Override
            public void onSuccess(HomePageBean homePageBean) {
                if (homePageBean.getPageNo() == 1) {
                    //设置其他数据
                    iHomePageView.toSetData(homePageBean);
                    //  创建精选课程适配器
                    HP_SelectedAdapter adapter_Selected = new HP_SelectedAdapter(context, homePageBean);
                    iHomePageView.toSetSelected(adapter_Selected);

                    //创建直播适配器
                    HP_LiveAdapter adapter_Live = new HP_LiveAdapter(context, homePageBean.getTodayLiveVideo());
                    iHomePageView.toSetLive(adapter_Live);

                    //创建最新课程适配器
                    list_DataBeanSave.clear();
                    list_DataBeanSave.addAll(homePageBean.getData());
                    adapter_New = new HP_NewAdapter(context, list_DataBeanSave, recyclerView);
                    iHomePageView.toSetNew(adapter_New);

                    //人气导师适配器
                    HP_TeacherLeft_Adapter adapter_TeacherLeft = new HP_TeacherLeft_Adapter(context, homePageBean);
                    iHomePageView.toSetTeacherLeft(adapter_TeacherLeft);

                    HP_TeacherRight_Adapter adapter_TeacherRight = new HP_TeacherRight_Adapter(context, homePageBean);
                    iHomePageView.toSetTeacherRight(adapter_TeacherRight);
                } else {
                    list_DataBeanSave.addAll(homePageBean.getData());
                    iHomePageView.toSetNew(adapter_New);
                }
            }
        });
    }
}
